package com.ww.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ww.mapper.UserMapper;
import com.ww.pojo.User;
import com.ww.pojo.UserVO;
import com.ww.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    @Resource
    private UserMapper userMapper;


    @Override
    public List<User> findalluser() {

        return userMapper.findalluser();
    }

    /**
     * 分页查询用户
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<User> userpage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> findalluser = userMapper.findalluser();
        return new PageInfo<>(findalluser);
    }

    /**
     * 用户登录
     * @param user_email
     * @param user_password
     * @return
     */
    @Override
    public User login(String user_email, String user_password) {
        User user = userMapper.queryByUserEmail(user_email);
        if(user==null||!user_password.equals(user.getUser_password())){
            log.info("执行登陆操作：【"+ user_email +"】用户名或密码输入错误");
            return null;
        }
        return user;
    }

    /**
     * 通过邮箱查找用户
     * @param uservo
     * @return
     */
    @Override
    public User queryemail(UserVO uservo) {
        return userMapper.queryByUserEmail(uservo.getUser_email());
    }

    @Override
    public int adduser(UserVO uservo) {
        return userMapper.adduser(uservo);
    }

    @Override
    public Boolean deleteuser(Integer user_id) {
        return userMapper.deleteuser(user_id);
    }


}
